#ifndef JPROCESSWATCHER_H
#define JPROCESSWATCHER_H

#include <JXQCore/JMessage>

namespace JXQ
{

class JListenThread;
class JProcessWatcherPrivate;

class JXQLIB_EXPORT JProcessWatcher
{
	J_MESSAGE(finished, int)

public:
	JProcessWatcher(JHandle pid);
	virtual ~JProcessWatcher();

public:
	int pid() const;
	bool wait(int *returnNumber, int msecs = -1);

protected:
	virtual void event(int returnNumber);

private:
	friend class JListenThread;
	JProcessWatcherPrivate *d_ptr;
};

class JProcessListenerPrivate;

class JXQLIB_EXPORT JProcessListener
{
	J_MESSAGE(finished, JHandle, int)

public:
	JProcessListener();
	virtual ~JProcessListener();

public:
	void addProcess(JProcessWatcher *watcher); //auto delete
	void addProcess(JHandle pid);

protected:
	virtual void event(JHandle pid, int returnNumber);

private:
	JProcessListenerPrivate *d_ptr;
};

} //namespace JXQ


#endif //JPROCESSWATCHER_H
